﻿<UserControl x:Class="MapViewer.ShapeView3D"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             KeyDown="Viewport_KeyDown">
    <UserControl.Resources>
        <MaterialGroup x:Key="TileMaterial">
            <DiffuseMaterial>
                <DiffuseMaterial.Brush>
                    <SolidColorBrush Color="#DD00FF00" />
                </DiffuseMaterial.Brush>
            </DiffuseMaterial>
            <SpecularMaterial SpecularPower="24">
                <SpecularMaterial.Brush>
                    <SolidColorBrush Color="#FF00FF00" />
                </SpecularMaterial.Brush>
            </SpecularMaterial>
        </MaterialGroup>
        <DiffuseMaterial x:Key="BackTileMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#DD00FF00" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
        <DiffuseMaterial x:Key="LandMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#EE660000" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
        <DiffuseMaterial x:Key="LandBackMaterial">
            <DiffuseMaterial.Brush>
                <SolidColorBrush Color="#88FF8888" />
            </DiffuseMaterial.Brush>
        </DiffuseMaterial>
    </UserControl.Resources>
    <Grid>
        <Border Grid.Column="1" Grid.Row="1" BorderBrush="Gray" BorderThickness="1" Margin="5" Background="White">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Border Grid.Column="1" Grid.Row="1" BorderBrush="Gray" BorderThickness="1" Margin="5" Background="White">
                    <Viewport3D x:Name="vp" 
                                    MouseMove="Viewport_MouseMove" 
                                    MouseWheel="Viewport_MouseWheel"
                                    KeyDown="Viewport_KeyDown">
                        <Viewport3D.Camera>
                            <PerspectiveCamera Position="{Binding CameraPosition}" 
                                           LookDirection="{Binding LookDirection}" />
                        </Viewport3D.Camera>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <Model3DGroup x:Name="mgRoot">
                                    <DirectionalLight Color="White" Direction="-2, -4, -1" />
                                    <Model3DGroup x:Name="mgShape">
                                        <Model3DGroup.Transform>
                                            <Transform3DGroup>
                                                <RotateTransform3D >
                                                    <RotateTransform3D.Rotation>
                                                        <AxisAngleRotation3D x:Name="anrX" Axis="1 0 0" />
                                                    </RotateTransform3D.Rotation>
                                                </RotateTransform3D>
                                                <RotateTransform3D>
                                                    <RotateTransform3D.Rotation>
                                                        <AxisAngleRotation3D x:Name="anrY" Axis="0 1 0" />
                                                    </RotateTransform3D.Rotation>
                                                </RotateTransform3D >
                                                <RotateTransform3D >
                                                    <RotateTransform3D.Rotation>
                                                        <AxisAngleRotation3D x:Name="anrZ" Axis="0 0 1" />
                                                    </RotateTransform3D.Rotation>
                                                </RotateTransform3D>
                                            </Transform3DGroup>
                                        </Model3DGroup.Transform>
                                    </Model3DGroup>
                                </Model3DGroup>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                    </Viewport3D>
                </Border>
                <StackPanel Grid.Row="2" Grid.Column="1">
                    <CheckBox Margin="5,5,5,0" Content="Transparency"
                          Checked="TransparencyCheckBox_Checked"
                          Unchecked="TransparencyCheckBox_Checked" />
                    <Label Content="Rotate" />
                    <DockPanel>
                        <Label DockPanel.Dock="Left" Content="X: " />
                        <Slider Minimum="0" Maximum="360" Value="{Binding ElementName=anrX, Path=Angle}" />
                    </DockPanel>
                    <DockPanel>
                        <Label DockPanel.Dock="Left" Content="Y: " />
                        <Slider Minimum="0" Maximum="360" Value="{Binding ElementName=anrY, Path=Angle}" />
                    </DockPanel>
                    <DockPanel>
                        <Label DockPanel.Dock="Left" Content="Z: " />
                        <Slider Minimum="0" Maximum="360" Value="{Binding ElementName=anrZ, Path=Angle}" />
                    </DockPanel>
                </StackPanel>
                <Slider Grid.Row="1" 
                Value="{Binding CameraPositionY, Mode=TwoWay}" 
                Orientation="Vertical" 
                Minimum="0" Maximum="1000" />
                <Slider Grid.Column="1"  
                Minimum="0" Maximum="1000" 
                Value="{Binding CameraPositionX, Mode=TwoWay}" />
                <Slider Grid.Column="2" Grid.Row="1"
                Orientation="Vertical"
                Value="{Binding CameraPositionZ, Mode=TwoWay}"
                Minimum="0" Maximum="1000" />
            </Grid>
        </Border>
    </Grid>
</UserControl>
